<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2025/2/26
 * Time: 9:26
 */

namespace app\modules\setting\configs\auth;


use app\common\enum\ConfigEnum;
use app\common\enum\EtcSellerTiktokProduct_shStatusEnum;
use app\common\enum\FormEnum;
use app\common\service\AuthChecker;
use sookie\react\handlers\UrlHandler;
use yii\helpers\ArrayHelper;

class ShsjcpConfig
{

    /**
     * @return array
     * 获取搜索表单配置
     */
    public static function getSearchConfig(){
        return [
            [
                "component" => "FormInput",
                "field" => "name",
                "label" => "产品名称",
                "placeholder" => "产品名称",
                "allowClear" => true,
            ],

        ];
    }

    /**
     * @return array
     * 获取表格的操作
     */
    public static function getTableActions(){
        return  [
        ];
    }

    /**
     * @return array
     * 获取表格行的操作
     * [] 表示要id, ["*"] 表示要一行记录,参数名record, ["id"] 指定需要的参数 ， selected_ids 表示需要所有选择的id
     * configParamsField 规定请求的时候带上数据行中的那些参数，只需要字段名
     */
    public static function getTableRowAction(){
        return [
            [
                "actionType" => "MODAL",
                "config" => [
                    "footer" => true,
                    "title" => "审核产品",
                    "alert" => [
                        "description" => "填写以下表单修改数据模型"
                    ]
                ],
                "configUri" => UrlHandler::toAction("auth/shsjcp","submit"),
                "auth" => AuthChecker::doPermissionCheck("auth/shsjcp","update"),
                "configParamsField" => ["id"],
                "label" => "审核产品"
            ],
        ];
    }

    /**
     * @return array
     * 获取表格配置
     */
    public static function getTableConfig(){
        return [
            "rowKey" => "id",
            "columns" => [
                [
                    "title" => "产品名称",
                    "dataIndex" => "name",
                    "sorter" => true,
                    "key" => "name",
                    "format" => "raw",
                ],
                [
                    "title" => "状态",
                    "dataIndex" => "sh_status",
                    "sorter" => true,
                    "key" => "sh_status",
                    "format" => "raw",
                ],
                [
                    "title" => "驳回原因",
                    "dataIndex" => "refuse_mark",
                    "sorter" => true,
                    "key" => "refuse_mark",
                    "format" => "raw",
                ],
                [
                    "title" => "最低价格",
                    "dataIndex" => "min_price",
                    "sorter" => true,
                    "key" => "min_price",
                    "format" => "text",
                ],
                [
                    "title" => "最高价格",
                    "dataIndex" => "max_price",
                    "sorter" => true,
                    "key" => "max_price",
                    "format" => "text",
                ],
                [
                    "title" => "达人佣金比例",
                    "dataIndex" => "creator_commission_percent",
                    "sorter" => true,
                    "key" => "creator_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "商家佣金比例",
                    "dataIndex" => "seller_commission_percent",
                    "sorter" => true,
                    "key" => "seller_commission_percent",
                    "format" => "text",
                ],
                [
                    "title" => "星级",
                    "dataIndex" => "product_rating",
                    "sorter" => true,
                    "key" => "product_rating",
                    "format" => "text",
                ],
                [
                    "title" => "评论",
                    "dataIndex" => "product_review_count",
                    "sorter" => true,
                    "key" => "product_review_count",
                    "format" => "text",
                ],
                [
                    "title" => "出售数",
                    "dataIndex" => "product_sales",
                    "sorter" => true,
                    "key" => "product_sales",
                    "format" => "text",
                ],
                [
                    "title" => "样品数量",
                    "dataIndex" => "sample_quota",
                    "sorter" => true,
                    "key" => "sample_quota",
                    "format" => "text",
                ],
            ],
            "actions" => self::getTableRowAction()
        ];
    }

    /**
     * 首页配置
     */
    public static function configIndex(){
        return [
            //搜索表单配置
            "searchConfig" => self::getSearchConfig(),
            // 操作配置 configParams 规定请求的时候带上那些参数
            "actionDivConfig" => self::getTableActions(),
            //表格配置
            "tableConfig" => self::getTableConfig(),
        ];
    }


    public static function configSubmit($model){
        return [
            "type" => "FORM",
            "formSubmitUri" => UrlHandler::toAction("auth/shsjcp","submit",["id" => $model->id]),
            "config" => [
                [
                    "component" => FormEnum::FormSelect,
                    "field" => "user_id",
                    "label" => "商家",
                    "placeholder" => "商家",
                    "allowClear" => true,
                    "initialValue" => $model->user_id."",
                    "rules" => [
                        [
                            "required" => true
                        ]
                    ],
                ],
                [
                    "component" => FormEnum::FormInput,
                    "field" => "link",
                    "label" => "产品分佣链接",
                    "placeholder" => "产品分佣链接",
                    "allowClear" => true,
                    "initialValue" => "",
                    "rules" => [
                        [
                            "required" => true,
                            "message" => "请填写产品分佣链接",
                        ]
                    ],
                ],
                [
                    "component" => FormEnum::FormRadio,
                    "field" => "sh_status",
                    "label" => "状态",
                    "placeholder" => "状态",
                    "allowClear" => true,
                    "initialValue" => $model->sh_status."",
                    "rules" => [
                        [
                            "required" => true
                        ]
                    ],
                    ConfigEnum::FORCE_OPTIONS =>[
                        strval(EtcSellerTiktokProduct_shStatusEnum::PASS) => '通过',
                        strval(EtcSellerTiktokProduct_shStatusEnum::REFUSE) => '驳回',
                    ],
                    "options" =>[
                        strval(EtcSellerTiktokProduct_shStatusEnum::PASS) => '通过',
                        strval(EtcSellerTiktokProduct_shStatusEnum::REFUSE) => '驳回',
                    ]
                ],
                [
                    "component" => FormEnum::FormMulInput,
                    "field" => "refuse_mark",
                    "label" => "驳回说明",
                    "placeholder" => "驳回说明",
                    "allowClear" => true,
                    "initialValue" => $model->refuse_mark."",
                    "rules" => [

                    ],
                ],
            ],
        ];
    }
}